package org.flashbrighton.as3bots.components
{
	import flash.display.Graphics;
	import flash.display.Loader;
	import flash.display.Shape;
	import flash.display.Sprite;
	
	public class ChassisComponent implements IComponent
	{
		private var _size:String;
		private var _skinImage:Sprite;
		private var _skin:Sprite;
		private var _radius:int;
		private var _density:Number = 1;
		private var _friction:Number = 1;
		private var _restitution:Number = 0.3;
		private var _loader:Loader;
				
		
		public function ChassisComponent(size:String, skinImage:Sprite=null)
		{
			_size = size;
			_skinImage = skinImage;
			setRadius();
			setSkin();
		}
		
		
		public function get size():String
		{
			return _size;
		}
		
		
		public function get skin():Sprite
		{
			return _skin;
		}
		
		
		public function get radius():int
		{
			return _radius;
		}
		
		
		public function get density():Number
		{
			return _density;
		}
		
		
		public function get friction():Number
		{
			return _friction;
		}
		
		
		public function get restitution():Number
		{
			return _restitution;
		}
		
		
		private function setRadius():void
		{
			switch (_size)
			{
				case ChassisSize.SMALL:
				_radius = 20;
				break;
				
				case ChassisSize.MEDIUM:
				_radius = 25;
				break;
				
				case ChassisSize.LARGE:
				_radius = 30;
				break;
			}
		}
		
		
		private function setSkin():void
		{
			_skin = new Sprite();
			
			if (_skinImage == null)
			{
				drawDefaultSkin();
			} 
			else
			{
				_skin.addChild(_skinImage);
			}			
		}
		
		
		private function drawDefaultSkin():void
		{
			var circle:Shape = new Shape();
			var g:Graphics = circle.graphics;
			
			g.lineStyle(2, 0x000000);
			g.beginFill(0xCCCCCC);
			g.drawCircle(0, 0, 100);
			g.endFill();
			g.moveTo(0, 0);
			g.lineTo(100, 0);
			_skin.addChild(circle);
		}

	}
}